<?php
	require_once './handler/check_session.php';
	
	$nbEmprunt= 1;
	
	if(isset($_GET['nbEmprunt'])){
		$nbEmprunt = $_GET['nbEmprunt'];
	}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en-US" lang="en-US">
    <head>
        <title>Nouveau Dossier</title>
        <meta http-equiv='Content-Type' content='text/html; charset=utf-8'/>
        <link rel="STYLESHEET" type="text/css" href="style/header_footer_style.css" />
        <link rel="STYLESHEET" type="text/css" href="style/dossier_style.css" />
        <link rel="STYLESHEET" type="text/css" href="style/calendar_style.css" />
        <script type="text/javascript" src="scripts/datepickr.js"></script>
        <script type="text/javascript" src="scripts/checkApi.js"></script>
        <script type="text/javascript">
			function manageCouverture() {
				var chomageBox = document.getElementById("chomage");
				var decesBox = document.getElementById("deces");
				var ptiaBox = document.getElementById("PTIA");
				var ittBox = document.getElementById("ITT");
				if(chomageBox.checked){
					decesBox.checked = "";
					decesBox.disabled = "true";
					ptiaBox.checked = "";
					ptiaBox.disabled = "true";
					ittBox.checked = "";
					ittBox.disabled = "true";
				} else {
					decesBox.checked = "checked";
					decesBox.disabled = "";
					ptiaBox.disabled = "";
					ittBox.disabled = "";
					chomageBox.checked = "";
					chomageBox.disabled = "true";
				}
			}			

			function checkFields(){
				 var listValueEmpty = ["date","nom", "prenom", "profession", "adresse1", "adresse3", "adresse4", "fumeur"];
				 var listValueEmptyEmprunt = ["montant", "taux",  "quotas", "duree"];
				 var listValueNumeric = ["montant", "quotas", "duree"];
				 var listValueNumeric2 = ["taux"];
				 var listValuePt = ["taux",  "quotas"];
				 var nbEmprunt = $('#nbEmprunt').val();
				 
				 var isgood = checkFieldsEmpty(listValueEmpty);
				
				 if(!isgood) return;

				 for(var i = 1; i <= nbEmprunt; i++)
				 {
					 var isgood = checkFieldsEmptyIndex(listValueEmptyEmprunt, i);
					 if(!isgood) return;
					isgood = checkFieldsNumericIndex(listValueNumeric, i);
					if(!isgood) return;
					isgood = checkFieldsNumericNotNullIndex(listValueNumeric2, i);
					if(!isgood) return;

					 isgood = checkPourcentageIndex(listValuePt, i);
					 if(!isgood)return;
					 
				 }

				
				 isgood = checkDate();
				
				 if(!isgood)return;
				 	
				 document.forms["new_dossier"].submit();

			}


			function addEmprunt(nbEmprunt){
				$("#nbEmprunt").val(nbEmprunt);
	        	$("#emprunt"+nbEmprunt).load('emprunttoinclude.php?nbEmprunt='+nbEmprunt); 
	        }

			function removeEmprunt(nbEmprunt){
				$("#nbEmprunt").val(nbEmprunt - 1);
				$("#emprunt"+(nbEmprunt)).load('emprunttoinclude.php?nbEmprunt='+(nbEmprunt-1)+" #emprunt"+(nbEmprunt)); 
	        }

			
		</script>

			
		</script>
		<script type='text/javascript' src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
    </head>
    <!-- BODY -->
    <body>
    	<!-- HEADER -->
        <?php require_once'./include/header.php'; ?>
        <!-- MAIN -->
		<div id="main">
			<form id='new_dossier' action='./handler/creation_treatment.php' method='post' accept-charset='UTF-8'>
			<div class='notify'></div>
			<fieldset id='fieldset_main'>
				<legend>NOUVELLE DEMANDE</legend>
				<fieldset class='fieldset_section'>
					<legend>Informations client</legend>
					<table>                         
						<tr>
							<td class='label'><label for='date' >Date*</label></td>
							<td class='input'><input type='text' name='date' id='date' value='<?php echo date('d-m-Y') ?>' maxlength="10" readonly="readonly" /></td>
							<td class='separator'><!-- SEPARETOR --></td>
							<td class='label'><label for='type_client' >Type de client</label></td>
							<td class='input'>
								<select class='fill' name='type_client' id='type_client'>
									<option value='null'></option>
									<option value='Particulier'>Particulier</option>
									<option value='Professionnel'>Professionnel</option>
								</select>
							</td>
						</tr>
						<tr>			
							<td class='label'><label for='societe' >Soci&eacute;t&eacute;</label></td>
							<td class='input'><input type='text' name='societe' id='societe' maxlength="50" /></td>
							<td class='separator'><!-- SEPARETOR --></td>
							<td class='label'><label for='numero_compte_client' >Num&eacute;ro de compte</label></td>
							<td class='input'><input type='text' name='numero_compte_client' id='numero_compte_client' maxlength="50" /></td>			
						</tr>			
						<tr>
							<td class='label'><label for='nom' >Nom*</label></td>
							<td class='input'><input type='text' name='nom' id='nom' maxlength="50" /></td>
							<td class='separator'><!-- SEPARETOR --></td>
							<td class='label'><label for='prenom' >Pr&eacute;nom*</label></td>
							<td class='input'><input type='text' name='prenom' id='prenom' maxlength="50" /></td>
						</tr>
						<tr>
							<td class='label'><label for='profession' >Profession*</label></td>
							<td class='input'><input type='text' name='profession' id='profession' maxlength="50" /></td>			
							<td class='separator'><!-- SEPARETOR --></td>
							<td class='label'><label for='date_naissance' >Date de naissance*</label></td>
							<td class='input'>
								<select name='jour_naissance'  id='jour_naissance'>
									<?php for ($jour = 1; $jour < 32; $jour++) { ?>
										<option value='<?php echo substr("00".$jour,-2); ?>'><?php  echo substr("00".$jour,-2); ?></option>
									<?php }?>
								</select>
								- <select name='mois_naissance' id='mois_naissance'>
									<?php for ($mois = 1; $mois < 13; $mois++) { ?>
										<option value='<?php echo substr("00".$mois,-2); ?>'><?php echo substr("00".$mois,-2); ?></option>
									<?php }?>
								</select>
								- <select name='annee_naissance'  id='annee_naissance'>
									<?php for ($annee = (date('Y')-90); $annee < (date('Y')-19); $annee++){ ?>
										<option value='<?php echo $annee; ?>'><?php echo $annee; ?></option>
									<?php }?>
								</select>
							</td>
						</tr>
						<tr>
							<td class='label'><label for='email' >Email</label></td>
							<td class='input'><input type='text' name='email' id='email' maxlength="50" /></td>
							<td class='separator'><!-- SEPARETOR --></td>
							<td class='label'><label for='tel_domicile' >Tel domicile</label></td>
							<td class='input'><input type='text' name='tel_domicile' id='tel_domicile' maxlength="50" /></td>
						</tr>
						<tr>
							<td class='label'><label for='adresse1' >Adresse / Rue*</label></td>
							<td class='input'><input type='text' name='adresse1' id='adresse1' maxlength="50" /></td>
							<td class='separator'><!-- SEPARETOR --></td>
							<td class='label'><label for='tel_portable' >Tel portable</label></td>
							<td class='input'><input type='text' name='tel_portable' id='tel_portable' maxlength="50" /></td>
						</tr>
						<tr>
							<td class='label'><label for='adresse2' >Adresse / Compl&eacute;ment</label></td>
							<td class='input'><input type='text' name='adresse2' id='adresse2' maxlength="50" /></td>
							<td class='separator'><!-- SEPARETOR --></td>
							<td class='label'><label for='cadre' >Cadre</label></td>
							<td class='input'>
								<select name='cadre' id='cadre' >
									<option value='0'>Non</option>
									<option value='1'>Oui</option>
								</select>
							</td>
						</tr>
						<tr>
							<td class='label'><label for='adresse3&4' >CP - Ville*</label></td>
							<td class='input'>
								<input type='text' class='cp' name='adresse3' id='adresse3' maxlength="5" />&nbsp;<input type='text' class='ville' name='adresse4' id='adresse4' maxlength="30" />
							</td>
							<td class='separator'><!-- SEPARETOR --></td>
							<td class='label'><label for='fumeur' >Fumeur*</label></td>
							<td class='input'>
								<select name='fumeur' id='fumeur' >
									<option value='0'>Non</option>
									<option value='1'>Oui</option>	
								</select>
							</td>
						</tr>
					</table>
				</fieldset>
				<input type='hidden' id='nbEmprunt' name='nbEmprunt' value='<?php echo $nbEmprunt?>'/>
				<div id="emprunt1">
				<?php include('./emprunttoinclude.php');?>
				</div>
				
				
				
				<fieldset class='fieldset_section'>
					<legend>Informations Emetteur</legend>
					<table>									
						<tr>
							<td class='label'><label for='nom_emetteur' >Nom du salari&eacute;</label></td>
							<td class='input'><input type='text' name='nom_emetteur' id='nom_emetteur' maxlength="50" /></td>
							<td class='separator'><!-- SEPARETOR --></td>
							<td class='label'><label for='prenom_emetteur' >Pr&eacute;nom du salari&eacute;</label></td>
							<td class='input'><input type='text' name='prenom_emetteur' id='prenom_emetteur' maxlength="50" /></td>
						</tr>
						<tr>
							<td class='label'><label for='numero_matricule_emetteur' >Numero du matricule</label></td>
							<td class='input'><input type='text' name='numero_matricule_emetteur' id='numero_matricule_emetteur' maxlength="50" /></td>
							<td class='separator'><!-- SEPARETOR --></td>
							<td class='label'><label for='numero_tel_emetteur' >Num&eacute;ro de T&eacute;l&eacute;phone</label></td>
							<td class='input'><input type='text' name='numero_tel_emetteur' id='numero_tel_emetteur' maxlength="50" /></td>
						</tr>
						<tr>
							<td class='label'><label for='agence_service_emetteur' >Agence / Service</label></td>
							<td class='input'><input type='text' name='agence_service_emetteur' id='agence_service_emetteur' maxlength="50" /></td>
							<td class='separator'><!-- SEPARETOR --></td>
							<td class='label'><label for='copie_emetteur' >Disribuer une copie &agrave;</label></td>
							<td class='input'><input type='text' name='copie_emetteur' id='copie_emetteur' maxlength="50" /></td>
						</tr>				
					</table>
				</fieldset>
				<?php if($_SESSION['user'] == 'admin') { ?>
				<fieldset class='fieldset_section'>
					<legend>Affectation</legend>
					<table>                         
						<tr>
							<td style="text-align: right;"><label>A quelle banque voulez-vous affecter cette demande :</label></td>
							<td class='separator'><!-- SEPARETOR --></td>
							<td style="text-align: left;">
								<select class='affectation' name='affectation_banque' id='affectation_banque'>
								<option value='null'></option>
									<?php foreach (Banque::getListAllBanque() as $banque){ ?>
										<option value='<?php  echo $banque->id ?>'><?php  echo $banque->nom ?>&nbsp;&nbsp;&nbsp;(<?php  echo $banque->login ?>)</option>
									<?php } ?>
								</select>
							</td>			
						</tr>
					</table>
				</fieldset>
				<?php } ?>
				<input type='hidden' name='statut' id='statut' value=0/>
				<div class='message'>* champs obligatoires</div>
				<div><input type='button' onclick="javascript:checkFields()" value='Valider' /></div>	
			</fieldset>
			</form>
            <script type="text/javascript">
                new datepickr('date', { 'dateFormat': 'd-m-Y', });	
			</script>
		</div>
		<!-- FOOTER -->
        <?php require_once'./include/footer.php'; ?>
    </body>
</html>
